(function(){"undefined"==typeof Math.sgn&&(Math.sgn=function(a){return 0==a?0:0<a?1:-1});var p={subtract:function(a,b){return{x:a.x-b.x,y:a.y-b.y}},dotProduct:function(a,b){return a.x*b.x+a.y*b.y},square:function(a){return Math.sqrt(a.x*a.x+a.y*a.y)},scale:function(a,b){return{x:a.x*b,y:a.y*b}}},z=Math.pow(2,-65),w=function(a,b){for(var f=[],d=b.length-1,g=2*d-1,h=[],e=[],l=[],i=[],k=[[1,0.6,0.3,0.1],[0.4,0.6,0.6,0.4],[0.1,0.3,0.6,1]],c=0;c<=d;c++)h[c]=p.subtract(b[c],a);for(c=0;c<=d-1;c++)e[c]=p.subtract(b[c+
1],b[c]),e[c]=p.scale(e[c],3);for(c=0;c<=d-1;c++)for(var m=0;m<=d;m++)l[c]||(l[c]=[]),l[c][m]=p.dotProduct(e[c],h[m]);for(c=0;c<=g;c++)i[c]||(i[c]=[]),i[c].y=0,i[c].x=parseFloat(c)/g;g=d-1;for(h=0;h<=d+g;h++){c=Math.max(0,h-g);for(e=Math.min(h,d);c<=e;c++)j=h-c,i[c+j].y+=l[j][c]*k[j][c]}d=b.length-1;i=t(i,2*d-1,f,0);g=p.subtract(a,b[0]);l=p.square(g);for(c=k=0;c<i;c++)g=p.subtract(a,u(b,d,f[c],null,null)),g=p.square(g),g<l&&(l=g,k=f[c]);g=p.subtract(a,b[d]);g=p.square(g);g<l&&(l=g,k=1);return{location:k,
distance:l}},t=function(a,b,f,d){var g=[],h=[],e=[],l=[],i=0,k,c;c=Math.sgn(a[0].y);for(var m=1;m<=b;m++)k=Math.sgn(a[m].y),k!=c&&i++,c=k;switch(i){case 0:return 0;case 1:if(64<=d)return f[0]=(a[0].x+a[b].x)/2,1;var q,n,i=a[0].y-a[b].y;c=a[b].x-a[0].x;m=a[0].x*a[b].y-a[b].x*a[0].y;k=max_distance_below=0;for(q=1;q<b;q++)n=i*a[q].x+c*a[q].y+m,n>k?k=n:n<max_distance_below&&(max_distance_below=n);n=c;q=0*n-1*i;k=(1*(m-k)-0*n)*(1/q);n=c;c=m-max_distance_below;q=0*n-1*i;i=(1*c-0*n)*(1/q);c=Math.min(k,i);
if(Math.max(k,i)-c<z)return e=a[b].x-a[0].x,l=a[b].y-a[0].y,f[0]=0+1*(e*(a[0].y-0)-l*(a[0].x-0))*(1/(0*e-1*l)),1}u(a,b,0.5,g,h);a=t(g,b,e,d+1);b=t(h,b,l,d+1);for(d=0;d<a;d++)f[d]=e[d];for(d=0;d<b;d++)f[d+a]=l[d];return a+b},u=function(a,b,f,d,g){for(var h=[[]],e=0;e<=b;e++)h[0][e]=a[e];for(a=1;a<=b;a++)for(e=0;e<=b-a;e++)h[a]||(h[a]=[]),h[a][e]||(h[a][e]={}),h[a][e].x=(1-f)*h[a-1][e].x+f*h[a-1][e+1].x,h[a][e].y=(1-f)*h[a-1][e].y+f*h[a-1][e+1].y;if(null!=d)for(e=0;e<=b;e++)d[e]=h[e][0];if(null!=g)for(e=
0;e<=b;e++)g[e]=h[b-e][e];return h[b][0]},x={},r=function(a,b){var f,d=a.length-1;f=x[d];if(!f){f=[];var g=function(a){return function(){return a}},h=function(){return function(a){return a}},e=function(){return function(a){return 1-a}},l=function(a){return function(b){for(var c=1,d=0;d<a.length;d++)c*=a[d](b);return c}};f.push(new function(){return function(a){return Math.pow(a,d)}});for(var i=1;i<d;i++){for(var k=[new g(d)],c=0;c<d-i;c++)k.push(new h);for(c=0;c<i;c++)k.push(new e);f.push(new l(k))}f.push(new function(){return function(a){return Math.pow(1-
a,d)}});x[d]=f}for(e=h=g=0;e<a.length;e++)g+=a[e].x*f[e](b),h+=a[e].y*f[e](b);return{x:g,y:h}},y=function(a,b){return Math.sqrt(Math.pow(a.x-b.x,2)+Math.pow(a.y-b.y,2))},s=function(a,b,f){for(var d=r(a,b),g=0,h=0<f?1:-1,e=null;g<Math.abs(f);)b+=0.005*h,e=r(a,b),g+=y(e,d),d=e;return{point:e,location:b}},v=function(a,b){var f=r(a,b),d=r(a.slice(0,a.length-1),b),g=d.y-f.y,f=d.x-f.x;return 0==g?Infinity:Math.atan(g/f)};window.jsBezier={distanceFromCurve:w,gradientAtPoint:v,gradientAtPointAlongCurveFrom:function(a,
b,f){b=s(a,b,f);1<b.location&&(b.location=1);0>b.location&&(b.location=0);return v(a,b.location)},nearestPointOnCurve:function(a,b){var f=w(a,b);return{point:u(b,b.length-1,f.location,null,null),location:f.location}},pointOnCurve:r,pointAlongCurveFrom:function(a,b,f){return s(a,b,f).point},perpendicularToCurveAt:function(a,b,f,d){b=s(a,b,null==d?0:d);a=v(a,b.location);d=Math.atan(-1/a);a=f/2*Math.sin(d);f=f/2*Math.cos(d);return[{x:b.point.x+f,y:b.point.y+a},{x:b.point.x-f,y:b.point.y-a}]},locationAlongCurveFrom:function(a,
b,f){return s(a,b,f).location},getLength:function(a){for(var b=r(a,0),f=0,d=0,g=null;1>d;)d+=0.005,g=r(a,d),f+=y(g,b),b=g;return f}}})();